<template>
  <view>
    <asset-info style="position: relative" :info="info"></asset-info>
  </view>
  <view
    v-if="info && (info.auditStatus == 'NO_PASS' || (info.auditStatus == 'PASS' && info.shelvesStatus == 1))"
    style="
      position: fixed;
      bottom: 0;
      width: 750rpx;
      height: 162rpx;
      background: #ffffff;
      border-top: 1rpx #f5f5f5 solid;
    ">
    <view v-if="info.auditStatus == 'PASS'" style="margin: 30rpx; display: flex">
      <view @click="onFocus" style="width: 129rpx">
        <image
          :src="`https://static.tospurfang.com/asset/${info.isConcern ? 'focused' : 'focus'}.png`"
          mode="scaleToFill"
          style="width: 55rpx; height: 64rpx; margin-left: 37rpx" />
        <view style="font-size: 24rpx; color: #222222; text-align: center">
          {{ info.isConcern ? '已关注' : '关注' }}
        </view>
      </view>
      <view style="flex: 1"></view>
      <view @click="onShare" class="btn" style="background: #042275">分享资产</view>
      <view @click="onCustomer" class="btn" style="background: #edb302; margin-left: 36rpx">推荐客户</view>
    </view>
    <view v-if="info.auditStatus == 'NO_PASS'" style="margin: 30rpx; display: flex">
      <view @click="showNoPassTip" class="btn" style="background: #042275; width: 333rpx">审核结果</view>
      <view @click="onReport" class="btn" style="background: #edb302; width: 333rpx; margin-left: 36rpx">
        重新编辑
      </view>
    </view>
  </view>
  <draw ref="drawRef" @path="onPath" @error="onError" />
  <image-modal ref="imageRef"></image-modal>
  <tip-modal ref="tipRef"></tip-modal>
</template>

<script setup>
  import { messageStore } from '@/biz/message'
  import assetInfo from '@/com/asset-info.vue'
  import imageModal from '@/com/image-modal.vue'
  import tipModal from '@/com/tip-modal.vue'
  import { onLoad } from '@dcloudio/uni-app'
  import { ref } from 'vue'
  import draw from '__com/draw/index.vue'
  import mgr from './biz'
  import optionMgr from './biz/option'

  const [drawRef, imageRef, tipRef] = [ref(), ref(), ref()]
  const info = ref()

  onLoad((opt) => {
    mgr.detail(opt.id).then((res) => {
      info.value = res
      if (res.image) {
        optionMgr.getOption(res).then((opt) => {
          drawRef.value.draw(opt)
        })
      }
      if (res.auditStatus == 'NO_PASS') {
        messageStore().read(res.propertyId)
        showNoPassTip()
      }
    })
  })

  function showNoPassTip() {
    tipRef.value.show({
      success: false,
      title: '审核不通过',
      content: `${info.value.auditContent}`
    })
  }

  function onPath(path) {
    info.value.showImage = path
  }

  function onShare() {
    if (info.value.showImage) {
      imageRef.value.show({ image: info.value.showImage, local: true })
    } else {
      uni.showToast({
        title: '该资产未上传资产图片，暂不支持分享',
        icon: 'none'
      })
    }
  }

  function onCustomer() {
    uni.reLaunch({ url: '/pages/index/customer' })
  }

  function onError(err) {
    uni.showToast({ icon: 'none', title: err.message })
  }

  function onFocus() {
    mgr.focus(info.value).then((res) => {
      info.value.isConcern = !info.value.isConcern
    })
  }

  function onReport() {
    uni.$once('getAssetInfo', () => {
      uni.$emit('assetInfo', { ...info.value, propertyId: null })
    })
    uni.navigateTo({ url: '/pages/asset/report' })
  }
</script>

<style lang="scss" scoped>
  .btn {
    width: 200rpx;
    height: 100rpx;
    line-height: 100rpx;
    border-radius: 16rpx;
    text-align: center;
    color: #ffffff;
  }
</style>
